package com.triplelink.jsons;

import java.io.File;
import java.io.FileNotFoundException;
import java.net.URISyntaxException;

import com.triplelink.util.GsonUtil;
import com.triplelink.util.IOUtil;

/**
 *	Returns jsons documents from files in work space.
 */
public final class JsonsTU
{
	private JsonsTU()
	{
		
	}
	
	private static String getStringSrc(String arquivoDaPasta)
	{
		try
		{
			File file = new File(JsonsTU.class.getResource(arquivoDaPasta).toURI());
			
			return IOUtil.getString(file);
		}
		catch (URISyntaxException e)
		{
			throw new RuntimeException(e);
		}
		catch (FileNotFoundException e) {
			
			throw new RuntimeException(e);
		}
	}
	
	
	public static String getString(String arquivoDaPasta) {
		return GsonUtil.getJsonObject(getStringSrc(arquivoDaPasta)).toString();
	}
	
	public static String getString(String arquivoDaPasta, Class<?> type) {
		
		return GsonUtil.getPrettyString(GsonUtil.getObject(getStringSrc(arquivoDaPasta), type));
	}
	
	public static <T extends Object> T getJsonAsBean(String arquivoDaPasta, Class<T> type) {
		
		return GsonUtil.getObject(getStringSrc(arquivoDaPasta), type);
	}
}
